import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import {resolve} from "path";
import {VueAmapResolver} from "@vuemap/unplugin-resolver";
// import * as path from "path";
// import * as fs from "fs";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 9527,   // 默认端口是 5173
    open: false,   // 启动后自动浏览器打开页面
    historyApiFallback: true,
    allowedHosts: "all",
    host: true,
    https: false, // 是否开启 https
    // host: 'niuma.com',
    // https: {
    //   key: fs.readFileSync(
    //     path.resolve(__dirname, 'D:/IT/jetbrains/webstorm/localhost-key.pem')  // 证书名字对应下载的证书路径名字
    //   ),
    //   cert: fs.readFileSync(
    //     path.resolve(__dirname, 'D:/IT/jetbrains/webstorm/localhost.pem')
    //   )
    // },
  },
  resolve: {
    // 设置文件./src路径为 @
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src')
      }
    ]
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        ElementPlusResolver({exclude: /^ElAmap[A-Z]*/}),
        VueAmapResolver()
      ],
      imports: [
        'vue',
        'vue-router',
      ]
    }),
    Components({
      resolvers: [
        ElementPlusResolver({exclude: /^ElAmap[A-Z]*/}),
        VueAmapResolver(),
      ],
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "./src/style/index.scss";`,
      }
    }
  }
})
